package com.zhouyu.mysql.lock;

import com.zhouyu.mysql.trx.Trx;
import lombok.Builder;
import lombok.Data;

import java.util.Objects;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 大都督周瑜（我的微信: dadudu6789）
 */
@Data
@Builder
public class Lock {
    private Trx trx;
    private Thread thread;
    private RecId recId;
    private int mode;  // 0: S，1: X
    private boolean isWait;
    private Object lock;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Lock lock1 = (Lock) o;
        return mode == lock1.mode && isWait == lock1.isWait && Objects.equals(trx, lock1.trx) && Objects.equals(thread, lock1.thread) && Objects.equals(recId, lock1.recId) && Objects.equals(lock, lock1.lock);
    }

    @Override
    public int hashCode() {
        return Objects.hash(thread, recId, mode, isWait, lock);
    }
}
